package com.clickpaas.materialsprocurement.dao.Impl;

import com.bizcloud.ipaas.t0ba0ba6afb694026b6b4e4e048af2b43.d20210202135416.codegen.CostcenterApi;
import com.bizcloud.ipaas.t0ba0ba6afb694026b6b4e4e048af2b43.d20210202135416.model.*;
import com.clickpaas.materialsprocurement.bean.MateralsDTOBean;
import com.clickpaas.materialsprocurement.dao.CostCenterDao;
import com.clickpaas.materialsprocurement.entity.CostCenterEntity;
import com.clickpaas.materialsprocurement.utils.SpringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

@Repository
@Slf4j
public class CostCenterDaoImpl implements CostCenterDao {

    @Resource
    private MateralsDTOBean materalsDtoBean;
    @Resource
    private CostcenterApi costcenterApi;

    /**
     * 根据条件查询成本中心数据
     *
     * @param costCenterEntity
     * @return List<CostCenterDTO1>
     */
    @Override
    public List<CostCenterDTOResponse> queryCostCenterInfo(CostCenterEntity costCenterEntity) {
        CostCenterDTO costCenterDTO = materalsDtoBean.costCenterDTO();
        try {
            SpringUtil.copyPropertiesIgnoreNull(costCenterEntity,costCenterDTO);
        }catch (Exception e){
            log.info("对象转换失败！转换的对象是：【{}】",costCenterEntity);
        }
        return queryShareInvent(costCenterDTO);
    }

    private List<CostCenterDTOResponse> queryShareInvent(CostCenterDTO costCenterDTO){
        DataResponseListCostCenterDTO costCenterUsingPOST = costcenterApi.findCostCenterUsingPOST(costCenterDTO);
        if(null == costCenterUsingPOST
                || null == costCenterUsingPOST.getData()
                || costCenterUsingPOST.getData().size()<=0
                || !"SUCCESS".equals(costCenterUsingPOST.getMessage())){
            log.info("当前查询的数据：【{}】",costCenterUsingPOST);
            return null;
        }
        return costCenterUsingPOST.getData();
    }

}
